package com.ffox.controller;

import com.ffox.entity.ClassTeacher;
import com.ffox.entity.Clazz;
import com.ffox.entity.StudentInformation;
import com.ffox.entity.Teachers;
import com.ffox.result.Result;
import com.ffox.service.SchoolStudentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/schoolStudent")
public class SchoolStudentController {

    @Autowired
    private SchoolStudentService schoolStudentService;

    // 1. 根据学校ID获取班级列表
    // 前端使用POST请求并通过params传递schoolNum参数
    @PostMapping("/getClassListBySchoolNum")
    public Result<List<Clazz>> getClassListBySchoolId(@RequestParam String schoolNum) {
        return schoolStudentService.getClassListBySchoolId(schoolNum);
    }

    // 2. 根据班级ID获取学生列表
    // 前端使用POST请求并通过params传递classId参数
    @PostMapping("/getStudentListByClassId")
    public Result<List<StudentInformation>> getStudentListByClassId(@RequestParam Long classId) {
        return schoolStudentService.getStudentListByClassId(classId);
    }

    // 3. 编辑班级信息
    // 前端通过params传递classId，通过请求体传递更新参数
    @PostMapping("/updateClass")
    public Integer updateClass(
            @RequestParam Long classId,
            @RequestBody Map<String, Object> params) {
        System.out.println("params======>" + params);
        return schoolStudentService.updateClass(classId, params);
    }

    // 4. 删除班级
    @PostMapping("/deleteClass")
    public Integer deleteClass(@RequestParam Long classId) {
        return schoolStudentService.deleteClass(classId);
    }

    // 5. 删除学生
    @PostMapping("/deleteStudent")
    public Integer deleteStudent(@RequestParam String studentIdCard) {
        return schoolStudentService.deleteStudent(studentIdCard);
    }

    // 6. 添加班级
    // 前端通过请求体传递班级信息
    @PostMapping("/addClass")
    public Integer addClass(@RequestBody Clazz classInfo) {
        return schoolStudentService.addClass(classInfo);
    }

    // 7. 添加学生
    @PostMapping("/addStudent")
    public Integer addStudent(
            @RequestParam String studentIdCard,
            @RequestParam Long classId) {
        System.out.println("访问到addStudent");
        return schoolStudentService.addStudent(studentIdCard, classId);
    }

    // 8. 获取学校教师列表
    // 修正接口路径与前端一致，参数名与前端匹配
    @PostMapping("/getTeacherListByschoolNum")
    public Result<List<Teachers>> getTeacherListBySchoolId(@RequestParam String schoolNum) {
        return schoolStudentService.getTeacherListBySchoolId(schoolNum);
    }

//    获取班级的代课老师
    @PostMapping("/getTeacherListByClassId")
    public Result<List<ClassTeacher>> getTeacherListByClassId(@RequestParam Long classId) {
        return schoolStudentService.getTeacherListByClassId(classId);
    }
//    更改班级代课老师
    @PostMapping("/updateSubjectTeacherByClassId")
    public Integer updateSubjectTeacherByClassId(
            @RequestParam Long classId,
            @RequestParam String courseName,
            @RequestParam String teacherId) {
        System.out.println("接收的数据"+classId+"--"+courseName+"--"+teacherId);
        return schoolStudentService.updateSubjectTeacherByClassId(classId, courseName, teacherId);

    }
}